/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.playground.client.websockets.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.playground.client.websockets.entity.message.request.RequestMessage;

/**
 *
 * @author Tiago Peres
 */
public class JsonUtil {
    private static GsonBuilder gsonBuilder;
    private static Gson gson;

    public static synchronized Gson getGson() {
        if (null == gson){
            buildGson();
        }
        return gson;
    }
    
    private static void buildGson(){
        gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(RequestMessage.class, new RequestMessageDeserializer());
        gson = gsonBuilder.create();
    }
}
